package com.eva.learn.concurrent.thinkInJava;

import java.util.concurrent.TimeUnit;

/**
 * 后台线程（守护线程）的finally子句并不保证会执行，当最后一个非后台线程终止，后台线程会突然终止
 * 
 * @author Evain.C
 *
 */

class ADaemon implements Runnable {

	@Override
	public void run() {
		try {
			// TimeUnit.SECONDS.sleep(1);
			System.out.println("Starting Adaemon");
			TimeUnit.SECONDS.sleep(1);
		} catch (InterruptedException e) {
			System.out.println("Exiting via InterruptedException");
		} finally {
			System.out.println("This should always run?");
		}
	}
}

public class DaemonsDontRunFinally {
	public static void main(String[] args) {
		Thread t = new Thread(new ADaemon());
		t.setDaemon(true);
		t.start();
	}
}
